package com.baitiaojun.moments.config;

import com.baitiaojun.api.util.ConstantUtil;
import org.redisson.Redisson;
import org.redisson.api.RBloomFilter;
import org.redisson.api.RedissonClient;
import org.redisson.config.Config;
import org.redisson.config.SingleServerConfig;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * @类名 RedissonConfig
 * @描述 TODO
 * @作者 白条君
 * @创建日期 2023/1/27 01:45
 * @版本 1.0
 */
@Configuration
public class RedissonConfig {

    @Value("${redisson.address}")
    private String address;

    @Value("${redisson.password}")
    private String password;

    @Bean
    public RBloomFilter<Object> bloomFilter() {
        Config config = new Config();
        SingleServerConfig singleServerConfig = config.useSingleServer();
        singleServerConfig.setAddress(this.address);
        singleServerConfig.setPassword(this.password);
        RedissonClient redissonClient = Redisson.create(config);
        RBloomFilter<Object> bloomFilter = redissonClient.getBloomFilter(ConstantUtil.BLOOM_FILTER_NAME);
        bloomFilter.tryInit(100000000L, 0.03);
        return bloomFilter;
    }
}
